package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.Notice2;
import cn.wolfcode.qo.Notice2QueryObject;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.service.INotice2Service;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.JsonResult;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/notice2")
public class Notice2Controller {

    @Autowired
    private INotice2Service notice2Service;
    @Autowired
    private IEmployeeService employeeService;

   // @RequiredPermission(name = "公告页面",expression = "notice2:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") Notice2QueryObject qo){
        PageInfo<Notice2> pageInfo = notice2Service.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "notice2/list";
    }




    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name="公告新增/编辑",expression = "notice2:saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Notice2 notice2){
        if (notice2.getId() != null) {
            notice2Service.update(notice2);
        }else {
            List<Employee> employees = employeeService.list();
            notice2Service.save(notice2,employees);
        }
        return new JsonResult();
    }
}
